<?php

	if(isset($_POST['btnCadastrar'])){
		require_once($_SERVER["DOCUMENT_ROOT"] .'Teste/Entities/Usuario.class.php');
		require_once($_SERVER["DOCUMENT_ROOT"] .'Teste/Business/UsuarioBO.class.php');		

		$login = filter_input(INPUT_POST, "edtLogin", FILTER_SANITIZE_MAGIC_QUOTES);
		$senha = filter_input(INPUT_POST, "edtSenha", FILTER_SANITIZE_MAGIC_QUOTES);
		$nome =filter_input(INPUT_POST, "edtNome", FILTER_SANITIZE_MAGIC_QUOTES);
		$descricao =filter_input(INPUT_POST, "edtDescricao", FILTER_SANITIZE_MAGIC_QUOTES);
		$opcao =filter_input(INPUT_POST, "rdTipo", FILTER_SANITIZE_MAGIC_QUOTES);

		$oUsuario = new Usuario($login,$senha);		
		$oUsuario->setNome($nome);
		$oUsuario->setDescricao($descricao);
		$oUsuario->setTipo($opcao);
		
		if(UsuarioBO::singleton()->cadastrar($oUsuario)){
			$msg = "Cadastrado com sucesso!";
		}else{
			$msg = "Erro ao cadastrar!";
		}	

	}
	if(!isset($_SESSION["usuario"])){
?>
		<table style="margin: 10px 150px;">
			<form acttion="?cadastrar=1" method="POST" id="input_formcadastro">
				<tr>
					<td>
						<label for="login">Email: </label>
					</td>
					<td>				
						<input type="text" name="edtLogin" class="input" id="edtLogin">
					</td>
				</tr>
				<tr>
					<td>		
						<label for="senha">Senha: </label>
					</td>
					<td>					
						<input type="text" name="edtSenha" class="input" id="edtSenha">
					</td>
				</tr>
				<tr>
					<td>			
						<label for="nome">Nome: </label>
					</td>
					<td>					
						<input type="text" name="edtNome" class="input" id="edtNome">
					</td>
				</tr>
				<tr>
					<td>			
						<label for="descricao">Descricao: </label>
					</td>
					<td>					
						<input type="text" name="edtDescricao" class="input" id="edtDescricao">
					</td>
				</tr>
				<tr>
					<td>			
						<label for="tipo">Tipo: </label>
					</td>
					<td>					
						<input type="radio" name="rdTipo" value="1" class="input" id="rdTipo" checked>Comprador<br>
						<input type="radio" name="rdTipo" value="0" class="input" id="rdTipo">Vendedor<br>
					</td>
				</tr>
				<tr>
					<td>			
						<label for="submit"></label>
					</td>
					<td>		
						<input type="submit" name="btnCadastrar" class="input_button" id="btnCadastrar" value="Cadastrar">
					</td>	
				</tr>
				<tr>
					<td colspan=2>	
				 		<?php
				 			echo (isset($msg)) ? $msg : "";
				 		?>			
				 	</td>		
				</tr>
		</table>
			</form>

<?php
	}
?>